/* 
 * libsaxychord
 * chord.h
 *
 * Choi Jonghwan<saxboy@saxboy.pe.kr>
 * 2005/02/19
 *
 * - Written in KLDP CodeFest :-)
 */

#ifndef __CHORD_H__
#define __CHORD_H__

#include "note.h"
#include "scale.h"
#include "parse.h"

/* FIXME: duplicated definitions. see parse.h */
/* common chord definitions */
typedef enum __chord_def {
	CHORD_NONE=0,  
	CHORD_MAJOR=1,  
	CHORD_MINOR=2, 
	CHORD_DOMINANT=3, 
	CHORD_HALFDIMINISHED=4, 
	CHORD_DIMINISHED=5, 
	CHORD_AUGMENTED=6, 
	CHORD_SUSPENDED=7, 
} CHORD_TYPE; 

/* we use some bit hack here. little bit dirty... :-P */
typedef enum __chord_var {
	CHORD_VAR_FLAT = 128, 
	CHORD_VAR_SHARP= 64, 

	CHORD_VAR_FIVE=5, 
	CHORD_VAR_SEVEN=7, 
	CHORD_VAR_NINE=9, 
	CHORD_VAR_ELEVEN=11, 
	CHORD_VAR_THIRTEEN=13, 
} CHORD_VARIATION; 

#define MAX_CHORD_NOTES 12
#define MAX_CHORD_VARS 4 /* power of 4 */
#define MAX_SCALES_PER_CHORD 12

typedef struct __CHORD {
	int note_count; 

	/* FIXME: ooopssss, what R U doin!!! */	
	NOTE root; 
	NOTE third; 
	NOTE fifth; 
	NOTE sixth; 
	NOTE seventh; 
	NOTE ninth; 
	NOTE eleventh; 
	NOTE thirteenth; 

	/* used only in sus chords */
	NOTE second; 
	NOTE fourth; 

	NOTE notes[MAX_CHORD_NOTES]; /* note pool */

	/* interval */
	_NOTE basenote; 
	int chord_def; 
	int chord_num;  /* 7, 9, 11, 13 */
	int chord_var_count; 
	int chord_var[MAX_CHORD_VARS]; 

	/* available scales 
	 * every chord maps to at least one scale. 
	 */

	/* FIXME: avoid notes? */	 
	int scale_count; 
	SCALE scales[MAX_SCALES_PER_CHORD]; 

} _CHORD; 
typedef _CHORD *CHORD; 


/* public chord API's */

CHORD chord_New(void);
CHORD chord_NewFromString(char *chordstr);
int chord_Delete(CHORD c);
int chord_ImportString(CHORD c, char *chordstr);
NOTE chord_BaseNote(CHORD c);
NOTE chord_ThirdNote(CHORD c);
NOTE chord_FifthNote(CHORD c);
NOTE chord_SeventhNote(CHORD c);
int chord_AddNote(CHORD c, NOTE n);
int chord_Print(CHORD c);
int chord_ExportToString(CHORD c, char *buf, int buflen); 
const char *chord_GetStaticString(CHORD c); 

int chord_CalculateScales(CHORD c); 
int chord_GetScaleCount(CHORD c); 
SCALE chord_GetScale(CHORD c, int i); 
int chord_AddScale(CHORD c, SCALE s); 

#endif /* __CHORD_H__ */



